package controllers
import (
	//"github.com/astaxie/beego"
	//"LiquidMeasurement/forms"
	"strconv"
	"fmt"
	m"LiquidMeasurement/models"
//	"github.com/astaxie/beego"
)

type BedDeviceController struct {
	//beego.Controller
	AdminController
}


func (this *BedDeviceController)Refresh()  {
	
}


func (this *BedDeviceController)HandleWarning()  {

}

func (this *BedDeviceController)GetDevicesInfo() {
	UserID := this.Ctx.Input.Param(":UserID")
	id, _ := strconv.ParseInt(UserID, 10, 64)
	admin, _ := m.GetAdminByUserID(id)
	data := GetAllDevicesInfo()
//	fmt.Println("BedDeviceController",data);
	fmt.Println("admin",data);
//	fmt.Println("admin",data[0].Device.);
	filter_department := make([]BedDeviceInfo, 0, 10000)
	filter_floor := make([]BedDeviceInfo, 0, 10000)

	if (admin.FilterDepartmentID != 0) {
		for _, v := range (data) {
			if v.Bed.Department_.Id == uint64(admin.FilterDepartmentID){
				filter_department = append(filter_department , v)

			}
		}
	}else{
		filter_department = data
	}
	if (admin.FilterFloor != 0) {
		for _, v := range (filter_department) {
			if v.Bed.Room_.Id == uint64(admin.FilterFloor){
				filter_floor = append(filter_floor , v)

			}
		}
	}else{
		filter_floor = filter_department
	}
			//mystruct := getAllDevicesInfo()
	fmt.Println("filter_floor",filter_floor)
	this.Data["json"] = &filter_floor
	this.ServeJSON()
}
func (this *BedDeviceController)ShowDevicesInfo()  {
	UserID := this.Ctx.Input.Param(":UserID")

	//data :=  GetAllDevicesInfo()

	this.Data["UserID"] = &UserID
	//mystruct := getAllDevicesInfo()
	this.TplName = "show_devices.html"
//	this.TplName = "display.html"
	return
}
func (this *BedDeviceController)AddBeds() {
	this.TplName = "admin_add_bed.html"
	return
}
